<template>
	<view class="user">
		<!-- 上方显示用户信息的区域 -->
		<view class="userinfo">
			<!-- 信息区域 -->
			<view class="top">
				<view class="avator">
					<uni-icons type="person-filled" size="60" :color="logColor"></uni-icons>
				</view>
				<view class="uname" v-if="store.isLogin">
					<view>{{store.userInfo.username}}</view>
					<view>{{store.userInfo.phone}}</view>
				</view>
				<view class="uname" v-else @tap="toLogin">点击登录</view>

			</view>
		</view>
		<!-- 下方显示的四项用户操作项 -->
		<view class="list">
			<uni-list>
				<uni-list-item v-for="item,index in manageList" :title="item.name" :show-extra-icon="true"
					:extra-icon="item.icon" clickable link @tap="navto(index)"></uni-list-item>
			</uni-list>
		</view>
	</view>

	<uni-popup ref="popup" type="dialog">
		<uni-popup-dialog title="通知" content="您确定要退出登录吗？" :duration="2000" @confirm="confirm"></uni-popup-dialog>
	</uni-popup>

</template>

<script setup>
	
	import {
		onLoad
	} from "@dcloudio/uni-app"
	import {
		ref
	} from 'vue'
	import {
		CONFIG
	} from "../../utils/config"

	import {
				userStore
			} from "../../store/userStrore.js"
	const store = userStore()
	const popup = ref(null)

	// 用户操作的渲染列表数据
	const manageList = ref([{
		name: '景点收藏',
		icon: {
			color: '#56c48b',
			size: '22',
			type: 'shop'
		}
	}, {
		name: '电影收藏',
		icon: {
			color: '#ff6700',
			size: '22',
			type: 'location-filled'
		}
	}, {
		name: '我的小组',
		icon: {
			color: '#ff6700',
			size: '22',
			type: 'location-filled'
		}
	}, {
		name: '修改密码',
		icon: {
			color: '#0225ff',
			size: '22',
			type: 'star'
		}
	}, {
		name: '退出登录',
		icon: {
			color: '#0081b9',
			size: '22',
			type: 'gear'
		}
	}])

	function toLogin() {
		uni.navigateTo({
			url: "/pages/login/login"
		})
	}


	function navto(index) {
		if (index == 4) {
			if (store.isLogin) {
				// popup.value.open()
				popup.value.open()

			}
		}
	}

	function confirm() {
		store.clearUserInfo()
	}

</script>

<style>
	body{
		background-color: gainsboro;
	}
	.user {
		height: 100vh;
		background-color: #ececec;
	}

	/* 上方区域的显示背景样式 */
	.user .userinfo {
		height: 160px;
		background-color: darkgray;
		border-radius: 0 0 10px 10px;
		/* 思考下面的样式有什么作用 */
		overflow: hidden;
	}

	/* 上方用户信息区域容器样式 */
	.user .userinfo .top {

		height: 100px;
		margin: 30px 40px;
		display: flex;
		align-items: center;
		color: #666;
	}

	/* 上方用户信息区域容器中头像的样式 */
	.user .userinfo .avator {
		background-color: #fff;
		width: 70px;
		height: 70px;
		border-radius: 50%;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 10px;
	}

	.user .list {
		background-color: #fff;
		margin: 10px;
		border-radius: 10px;
	}
</style>